package com.wtpm.sys.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fwk.spbt.service.BaseService;
import com.fwk.spbt.vo.RequestPageVO;
import com.fwk.spbt.vo.ResponsePageVO;
import com.wtpm.sys.entity.SysMenu;
import com.wtpm.sys.entity.SysUser;
import com.wtpm.sys.mapper.SysMapper;
import com.wtpm.sys.service.IUserService;
import com.wtpm.sys.util.SysUtil;
import com.wtpm.sys.vo.LoginMenuVO;
import com.wtpm.sys.vo.SysUserVO;

@Service
public class UserService extends BaseService implements IUserService {
	@Autowired
	private SysMapper sysMapper;

	@Override
	public SysUser checkUser(String userId, String pwd) {
		SysUser sysUser = new SysUser();
		sysUser.setId(userId);
		sysUser.setPassword(pwd);
		return sysMapper.checkUser(sysUser);
	}

	@Override
	public void addUser(SysUserVO vo) {
		SysUser user = new SysUser();
		sysMapper.addUser(user);
	}

	@Override
	public ResponsePageVO<SysUserVO> queryUserpage(RequestPageVO<SysUserVO> reqDTO) {
		List<SysUser> list = sysMapper.findUserPage(reqDTO.getPageNum(), reqDTO.getPageSize());
		ResponsePageVO<SysUser> page = pageInfo(list, reqDTO.getPageSize());
		System.out.print(page.getTotal());
		return null;
	}

	@Override
	public List<LoginMenuVO> queryMenuByUser(String userId) {
		List<SysMenu> menus = sysMapper.queryMenuByUser(userId);
		List<LoginMenuVO> list = list(menus, LoginMenuVO.class);
		LoginMenuVO root = new LoginMenuVO();
		root.setId("ROOT");
		SysUtil.toMenuTree(root, list);
		return root.getRoutes();
	}

}
